package day15;

import java.util.*;

public class HomeWork { }

class A3{
    public static void main(String[] args) {
        String str = "If you want to change your fate I think you must come to the ujiuye to learn java";
        String[] words = str.split(" ");
        Map<String, Integer> map = new HashMap<>();
        for (String word : words) {
            if (map.containsKey(word)) {
                map.put(word, map.get(word) + 1);
            } else {
                map.put(word, 1);
            }
        }
        System.out.println("出现次数为:");
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            System.out.println(entry.getKey() + "=" + entry.getValue());
        }
    }
}

class B3{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入创建对象的个数");
        int n = sc.nextInt();
        Players[] players = new Players[n];
        for (int i = 1; i <= n; i++) {
            players[i-1] = Players.get();
            System.out.println("第"+i+"个:"+players[i-1]);
        }
    }
}

class  Players{
    private static int n=-1;
    private static Players[] player = new Players[11];
    private Players(){}
    public static Players get(){
        for (int i = 0; i < player.length; i++) {
            if (player[i] == null) {
                player[i] = new Players();
                return player[i];
            }
        }
        if (n==10){
            n=0;
        }
        else {
            n++;
        }
        return player[n];
    }
}

class A4{
    public static void main(String[] args) {
        System.out.println("第五个人年龄:"+GetAge(5));
    }
     static int GetAge(int agenum){
        if (agenum==1){
            return 10;
        }
        else{
            return GetAge(agenum-1)+2;
        }
    }
}


class B4{
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        System.out.println("请输入商品名称:");
        while (true){
            Scanner sc = new Scanner(System.in);
            String goods = sc.next();
            if ("end".equals(goods)) {
                break;
            }
            if (map.containsKey(goods)) {
                map.put(goods, map.get(goods) + 1);
            }
            else {
                map.put(goods, 1);
            }
        }
        List<Map.Entry<String, Integer>> list = new ArrayList<>(map.entrySet());
        list.sort((o1, o2) -> o2.getValue()-(o1.getValue()));
        for (Map.Entry<String, Integer> entry : list) {
            System.out.println("商品名:"+entry.getKey() + ",售卖数量:" + entry.getValue());
        }
    }
}
